<?php  $pharmacy_id = $_SESSION['acc_id'];       
       $owner_id = $pharmacy_id;
       //echo $owner_id;
       
?>
<div class="row-fluid">   
        <form action="#" method="post" name="frmlist">
            <div class="title"><h4><?php echo $lang['PROMOTION_TITLE']; ?></h4></div>

            <div >
                <div>                   
                    <input class="btn" type="button" name="btnadd" value="Add" onClick="javascript:window.location.href='index.php?view=add_promotion&amp'; return false;" />
                </div>
            </div>

            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                <tr>
                    <th width="5%" align="center">No</th>
                    <th width="20%" align="center">Product name</th>
                    <th width="15%" align="center">Scan code</th> 
                    <th width="15%" align="center">Quantity</th>
                    <th width="17%" align="center">Date in stock</th>
                    <th width="12%" align="center">%promotion</th>
                    <th width="30%" align="center">Actions</th>
                </tr>
            </table>

            <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center" class="table table-striped table-hover">
                <?php
                $qstring = '';
                $rowsPerPage = isset($_GET['num']) ? $_GET['num'] : '10';
                $sql = "SELECT p.*, phar.*, pro.* FROM promotion AS pro,tblproduct AS p, tblpharmacy AS phar WHERE phar.user_id = p.owner AND pro.product_id = p.id AND p.owner = $owner_id GROUP BY pro.product_id ORDER BY pro.promotion_id ASC";
                $result = mysql_query(getPagingQuery($sql, $rowsPerPage));
                $pagingLink = getPagingLink($sql, $rowsPerPage, $qstring);
                $i = 1;
                $n = 0;
                $page = (!empty($_GET['page'])) ? $_GET['page'] : '0';
                $nomlist = (!empty($page)) ? $rowsPerPage * $page - 10 : '0';
                while ($row = mysql_fetch_assoc($result)) {
                    $n ++;
                    extract($row);

                    if ($i % 2) {
                        $class = 'row1';
                    } else {
                        $class = 'row2';
                    }
                    ?>
                    <tr class="<?php echo $class; ?>">                                               
                        <td class="p_l" width="5%" align="center"><?php echo $n + $nomlist; ?></td>
                        <td class="p_l" width="20%" align="center"><?php echo $row['product_name'] ?></td>
                        <td class="p_l" width="15%" align="center"><?php echo $row['scan_code'] ?></td>
                        <td class="p_l" width="15%" align="center"><?php echo $row['quantity'] ?></td> 
                        <td class="p_l" width="17%" align="center"><?php echo $row['date_in_stock'] ?></td>
                        <td class="p_l" width="12%" align="center"><?php echo $row['promotion'] ?></td> 
                        <td class="p_l" width="30%" align="center"><div class="btn-group"><a title="edit" class="btn btn-primary btn-inverse" href="index.php?view=edit_promotion&id=<?php echo $row['promotion_id'] ?>"><i class="icon-pencil icon-white"></i></a>       
                                <a title="delete" onclick="return confirm('Are you sure you want to delete?')" class="btn btn-primary btn btn-danger" href="index.php?view=delete_promotion&id=<?php echo $row['promotion_id'] ?>"><i class="icon-trash icon-white"></i></a> 
                    </tr>
                    <?php
                    $i++;
                    
                } //end while
                ?>   

            </table>
            <div class="row-fluid">
                <div class="span7">
                    <div class="wp-pagenavi">
                        <?php echo $pagingLink; ?>
                        <div class="clear"></div>
                    </div>
                </div>
                <div class="span3 offset2">
                    view per page
                    <select class="right span4" name="numpage" onchange="javascript:viewByNumPage();">
                        <option value="10" <?php echo($rowsPerPage == 10) ? ' selected="selected"' : ''; ?>>10</option>
                        <option value="20" <?php echo($rowsPerPage == 20) ? ' selected="selected"' : ''; ?>>20</option>
                        <option value="30" <?php echo($rowsPerPage == 30) ? ' selected="selected"' : ''; ?>>30</option>
                        <option value="40" <?php echo($rowsPerPage == 40) ? ' selected="selected"' : ''; ?>>40</option>
                        <option value="50" <?php echo($rowsPerPage == 50) ? ' selected="selected"' : ''; ?>>50</option>        
                    </select>
                </div>            
            </div> 

        </form>   
</div>
